Public Class ctrReference
    Public Event ValueChanged(ByVal sender As ctrReference)
    Public UserDidIt As Boolean = False
    Private Sub txtValue_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTag.TextChanged
        If UserDidIt Then RaiseEvent ValueChanged(Me)
    End Sub

    Private Sub txtBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBrowse.Click
        Dim selectTag As New frmTag
        MagicInterface.DisplayTreeDB(selectTag.trvTags, files)
        If selectTag.ShowDialog = DialogResult.OK Then
            txtTag.Text = selectTag.trvTags.SelectedNode.FullPath
        End If
    End Sub

    Private Sub txtOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtOpen.Click
        Dim Found As Boolean = False
        Dim tagDetail(1) As String
        tagDetail(0) = txtTag.Text.Replace(System.IO.Path.GetExtension(txtTag.Text), "")
        tagDetail(1) = cxpe.FromExtension(System.IO.Path.GetExtension(txtTag.Text).Replace(".", "")).FourCC

        Dim tagIndex As Integer = magicMap.Library.IndexByName(tagDetail(0), tagDetail(1))
        For Each tP As TD.SandDock.TabbedDocument In MainForm.tabManager.Documents
            If tP.Tag = tagIndex Then
                Found = True
                tP.Select()
            End If
        Next
        If Not Found Then
            Dim mTag As Magic.Core.Tag = magicMap.Library(tagIndex)
            Dim tTag As New ctrTag(mTag, mTag.Xpe)
            Dim tPage As New TD.SandDock.TabbedDocument(MainForm.tabManager, tTag, System.IO.Path.GetFileName(txtTag.Text))
            tPage.Open()
            tPage.Tag = tagIndex
        End If
    End Sub
End Class
